/*
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-08-23 20:28:33
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-08-23 22:43:28
 * @FilePath: \crm_customer\src\utils\axios.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Axios from "axios";
import store from "../store";

const axios = Axios.create({
  // http://43.142.187.211:8080   // 合代码后的地址
  //101.43.12.99:8080商品进销存
  baseURL: "http://43.142.187.211:8080",
  //  baseURL: "http://47.108.219.53:8080",
  // baseURL: "http://1.117.227.212:8080"
  // http://1.117.227.212:8080   // 原先接口地址
  // http://43.142.194.41:8080    // 发送请求地址
  // http://43.142.187.211:8080   // 登录地址
 
});
// axios.defaults.headers.post['Content-Type'] = 'application/json'
// 拦截Axios发起的所有请求，通过dispatch修改isLoading为true
axios.interceptors.request.use(
    (config) => {
        config.headers["Authorization"] = store.userStore.token;
        //需要把token添加到header中
        return config;
    },
    (err) => {
        return Promise.reject(err);
    }
);
//拦截Axios发起的所有响应，通过dispatch修改isLoading为false
axios.interceptors.response.use((config) => {
    //需要将token 存起来
    if (config.data.authorization) {
        store.userStore.token = config.data.authorization;
        sessionStorage.setItem("token", config.data.authorization);
    }

    return config;
});

export default axios;
